//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================


namespace Shp.Runtime.Sitka.ServiceAgent
{
    using System;
    using Shp.Runtime.Sitka.ServiceGateway.SitkaClient;
    using Shp.Runtime.Sitka.ServiceAgent.Managers;
    using Shp.Runtime.Sitka.ServiceAgent.Factories;

    public static class SitkaProxyFactory
    {
        public static ISitkaSoapService BuildProxy()
        {
            ProviderFactory<ITenantManager, DefaultTenantManager> factory = new ProviderFactory<ITenantManager, DefaultTenantManager>();
            return BuildProxy(factory.Build("TenantManager"));
        }

        public static ISitkaSoapService BuildProxy( ITenantManager tenantManager )
        {
            ProviderFactory<ISitkaSoapService, SitkaSoapServiceClient> factory = new ProviderFactory<ISitkaSoapService, SitkaSoapServiceClient>();
            ISitkaSoapService proxy = factory.Build("SitkaProxy");

            SitkaSoapServiceClient sitkaProxy = proxy as SitkaSoapServiceClient;
            
            if (sitkaProxy != null)
            {
                sitkaProxy.ClientCredentials.UserName.UserName = tenantManager.UserName;
                sitkaProxy.ClientCredentials.UserName.Password = tenantManager.Password;
            }

            return proxy;       
        }
    }
}
